<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

if(Antz_IntelliForm::submitted('create-block')){
    $error = false;
    $tagname = preg_replace('/[^a-zA-Z0-9\_]/', '', post('tagname'));

    if(trim($tagname)==''){
        $error = true;
        JFX::addFormError('tagname', 'Must not be empty!');
        JFX::addError('Tag Name cannot be empty!');
    }

    if($DB->countRows($CONFIG->dbprefix.'cst_tags', "tagname = '{$tagname}'")>0){
        $error = true;
        JFX::addFormError('tagname', 'Already registered');
        JFX::addError('Tag Name is already a tag');
    }

    if(!$error){
        $dbParams = array(
            'tagname' => $tagname,
            'code' => $_POST['tagcontent']
        );
        $DB->insert($CONFIG->dbprefix.'cst_blocks', $dbParams);
        JFX::addSuccess('Your block has been created');
        die('<script type="text/javascript">
if(window.parent) window.parent.location = "'.$url.'";
</script>');
    }






}











$formFields = array(
    array(
        'name' => 'tagname',
        'value' => post('tagname'),
        'type' => 'text',
        'label' => 'Tag Name'
    ),
    array(
        'name' => 'tagcontent',
        'value' => array_key_exists('tagcontent', $_POST) ? $_POST['tagcontent'] : '',
        'type' => 'code',
        'id' => 'tagcontent',
        'class' => 'php',
        'label' => 'Tag Code'
    ),
    array(
        'type' => 'submit',
        'value' => 'Create tag',
        'label' => '&nbsp;',
        'name' => 'submitBtn'
    )
);

echo JFX::makeRapidForm($formFields, 'New Block Details', 'create-block');


